package com.eastfair.matching.enumeration;

import com.eastfair.annotation.base.LanguageTypeEnum;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.code.BaseExceptionCode;

/**
 * @Author lyw
 * @Date 2022/8/11 18:16
 */

public enum MatchingExceptionCode implements BaseExceptionCode {


    /**
     * 服务是商集合不能为空
     */
    NOT_SERVICE_PROVIDER_NULL(13001001, "服务是商集合不能为空", ""),
    /**
     * 用户id集合不能为空
     */
    NOT_USER_ID_NULL(13001002, "用户id集合不能为空", ""),

    /*
     *****************************************
     */
    NOT_ROLE_MENU_NULL(13006001,"角色菜单不能为空",""),

    ;

    private final int code;
    /**
     * 中文消息
     */
    private String msg;
    /**
     * 英文消息
     */
    private String enMsg;

    MatchingExceptionCode(int code, String msg, String enMsg) {
        this.code = code;
        this.msg = msg;
        this.enMsg = enMsg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        //中英文切换
        if (LanguageTypeEnum.CN.name().equals(ContextUtil.getLanguageType())) {
            //中文
            return msg;
        } else if (LanguageTypeEnum.EN.name().equals(ContextUtil.getLanguageType())) {
            //英文
            return enMsg;
        }
        return msg;
    }



    public MatchingExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }


    public MatchingExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }
}
